<template>

	<view class="map-content">
		<view class="content-popup" @touchmove.stop.prevent="clear" v-if="detailsShow">
			<view class="popup-top">
				<view class="popup-title">{{pubData.jobTitle}}</view>
				<view class="popup-x" @click="detailsClose">×</view>
			</view>
			<view class="popup-top">
				<view class="">详细地址：{{pubData.jobAddress}}</view>
			</view>
			<view class="btn" @click="navigate('/page_other/job_hunting/job_detail/index?id='+pubData.id)">详情</view>

		</view>
		<view class="article-tab" style="display: flex; width: 300rpx;border: 1px solid red;justify-content: center;">
			<view @click.prevent="noticeActive=1" :class="noticeActive===1?'active':''" class="tab-item">地图模式</view>
			<view @click.prevent="noticeActive=2" :class="noticeActive===2?'active':''" class="tab-item">列表模式</view>
		</view>
		<map :longitude="mapData.longitude" :latitude="mapData.latitude" :circles="mapData.circles"
			:markers="mapData.markers" scale="13" @markertap="markertap" v-if="noticeActive==1"></map>
		<!-- <view class="list" v-if="noticeActive!=1">
			<template v-if="incubatorsList.length>0">
				<view class="list-item" @click="navigate('/page_other/serve/incubation_base_detaail?id='+item.id)"
					v-for="item in incubatorsList" :key="item.id">
					<view class="left">
						<view class="title FangZhengHanZhenGuangBiaoJianTi" style="font-size: 30rpx;">
							{{item.name}}
						</view>
						<view class="site">
							{{item.address}}
						</view>
					</view>
					<view class="right">
						<view class="more iconfont icon-gengduo1">
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/cyfw/%E6%9B%B4%E5%A4%9A.png"
								mode=""></image>
						</view>
					</view>
				</view>
			</template>
			<view v-else class="block list-block">
				<view class="empty">暂无数据</view>
			</view>
		</view> -->
		<view class="list" v-if="noticeActive==2">
			<template v-if="baseList.length>0">
				<view class="info-list" v-for="item in baseList" :key="item.id">
					<view class="info-item">
						<image class="info-icon" :src="imageUrl+'/home/school.png'"></image>
						<view class="info-title">{{item.baseName}}</view>
					</view>
					<view class="menu-item">
						<view class="menu-list" v-for="item1 in menuList" :key="item1.id"  v-if="item.id>5"
							@click="menuJump(item1.url,item.id,item1.id)">
							<view class="menu">{{item1.title}}</view>
						</view>
						<view class="menu-list" v-for="item1 in menuList" :key="item1.id"  v-if="item.id<6&&item1.id>1"
							@click="menuJump(item1.url,item.id,item1.id)">
							<view class="menu">{{item1.title}}</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else class="block list-block">
				<view class="empty">暂无数据</view>
			</view>
		</view>
	</view>
	</view>

</template>

<script>
	import {
		getPublishApi,
		findAllJobById
	} from '@/api/job_hunting.js';
	import {
		getIncubatorsListApi,
		getIncubatorsByIdApi,
		getIncubatorsArticleByFatherIdApi,
		getAreaBaseListApi
	} from '@/api/incubation_base.js';
	export default {
		props: {
			// 高度
			boxHeihgt: {
				type: Number,
				default: 0
			},
			// 背景色
			bgColor: {
				type: String,
				default: "#F2F6FF"
			},
			// 控制初始是否显示
			startShow: {
				type: Boolean,
				default: false
			},
			// 是否显示线
			showLine: {
				type: Boolean,
				default: true
			},
			// 上下滑动 超过多少距离触发 updownDistance
			updDistance: {
				type: Number,
				default: 160
			},
		},
		watch: {
			'startShow': {
				handler(n, o) {
					this.isHide = !n;
				},
				deep: true,
				immediate: true
			},
			noticeActive: {
				handler(val) {
					// if (val != 1) {
					// 	this.getListDrop()
					// } else {
					// 	this.oderDate = 0;
					// 	this.orderDistance = 1;
					// }
					this.noticeActive = val
					this.getAreaBaseList()
				},
				immediate: true
			},
		},
		data() {
			return {
				menuList: [{
						id: 1,
						title: '基地情况简介',
						url: '',
						url: '/page_other/serve/base_detail'
					},
					{
						id: 2,
						title: '基地管理办法',
						url: '/page_other/serve/base_detail'
					},
					{
						id: 3,
						title: '孵化基地列表',
						url: '/page_other/serve/base_list'
					}
				],
				baseList: [],
				incubatorsList: [],
				oderDate: 1,
				orderDistance: 0,
				list: [],
				page: 1,
				limit: 4,
				noticeActive: 1,
				latitude: 0,
				longitude: 0,
				pubData: {
					jobTitle: '',
					jobAddress: ''
				},
				mapData: {
					longitude: 98.510165,
					latitude: 39.737452,
					// circles: [{
					// 	latitude: '',
					// 	longitude: '',
					// 	color: '#7cb5ec88',
					// 	fillColor: '#7cb5ec88',
					// 	radius: 800,
					// 	strokeWidth: 2
					// }],
					markers: [{

					}],
				},
				minHeight: 90,
				translateY: 70,
				isHide: true,
				boxPadBottom: 0,
				// 根据滑动设置位置
				changeTop: 0,
				// 是否固定高度
				showMax: false,
				// 记录起始位置
				startData: {
					clientX: '',
					clientY: ''
				},
				detailsShow: false,
				imageUrl: ''
			}
		},
		methods: {
			getAreaBaseList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getAreaBaseListApi({}).then((res) => {
					uni.hideLoading()
					this.baseList = res
				})
			},
			clear(e) {
				e.stopPropagation();
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			menuJump(url, id, type) {
				uni.navigateTo({
					url: url + '?id=' + id + '&type=' + type
				})
			},
			markertap(e) {
				console.log(e)
				let markerId = e.detail.markerId;
				if (markerId > 0) {
					this.navigate('/page_other/serve/incubation_base_detaail?id=' + markerId)
				}

			},
			detailsClose() {
				this.detailsShow = false;
			},
			// 当按下去的时候
			fingerstart(e) {
				// 记录 距离可视区域左上角 左边距 和 上边距
				this.startData.clientX = e.changedTouches[0].clientX;
				this.startData.clientY = e.changedTouches[0].clientY;

			},
			// 当抬起来的时候
			fingerend(e) {

				// 当前位置 减去 按下位置 计算 距离
				const subX = e.changedTouches[0].clientX - this.startData.clientX;
				const subY = e.changedTouches[0].clientY - this.startData.clientY;
				if (subY > this.updDistance || subY < -this.updDistance) {
					if (subY > this.updDistance) {
						// this.bottomscroll(subY);
						this.showMax = false;
						this.getDomTop()
					} else if (subY < -this.updDistance) {
						// this.topscroll(subY);
						this.showMax = true;
						this.getDomTop()
					}
				}
			},
			// 获取元素的top值
			getDomTop() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.detailBox').boundingClientRect(data => {
					if (data) {
						// 上滑
						this.translateY = 0;
						if (this.showMax) {} else {
							// 下滑
							this.translateY = 70;
						}
					}
				}).exec();
			},
			chosenPosition() {
				uni.getLocation({
					isHighAccuracy: true,
					success: (current) => {
						this.mapData.latitude = current.latitude;
						this.mapData.longitude = current.longitude;
						this.mapData.markers[0].latitude = current.latitude;
						this.mapData.markers[0].longitude = current.longitude;
						// this.mapData.circles[0].latitude = current.latitude;
						// this.mapData.circles[0].longitude = current.longitude;
					},
					fail: (e) => {
						this.showToast('获取位置失败，请重试！');
					}
				})
			},
			getList() {
				this.latitude = uni.getStorageSync('latitude')
				this.longitude = uni.getStorageSync('longitude')
				let config = {
					// page: this.page,
					// limit: this.limit,
					// orderDistance: 1,
					latitude: this.latitude,
					longitude: this.longitude
				}
				getIncubatorsListApi({}).then((res) => {
					this.incubatorsList = res
				})
			},
			getList() {
				this.latitude = uni.getStorageSync('latitude')
				this.longitude = uni.getStorageSync('longitude')
				let config = {
					// page: this.page,
					// limit: this.limit,
					// orderDistance: 1,
					latitude: this.latitude,
					longitude: this.longitude
				}
				getIncubatorsListApi(config).then((res) => {
					this.incubatorsList = res.incubatorsList ?? [];

				})
			},
			findAllJob(id) {
				findAllJobById({
					id: id
				}).then((res) => {
					this.pubData = res ?? [];
				}).catch((res) => {
					console.log(res)
				})
			},
			getListDrop() {
				this.latitude = uni.getStorageSync('latitude')
				this.longitude = uni.getStorageSync('longitude')
				let config = {
					// page: 1,
					// limit: 100,
					// orderDistance: 1,
					// latitude: this.latitude,
					// longitude: this.longitude
				}

				getIncubatorsListApi(config).then((res) => {
					let incubatorsList = res ?? [];
					if (incubatorsList && incubatorsList.length > 0) {

						for (var i = 0; i < incubatorsList.length; i++) {
							var vote = {};
							vote.id = incubatorsList[i].id;
							vote.longitude = incubatorsList[i].longitude;
							vote.latitude = incubatorsList[i].latitude;
							vote.title = incubatorsList[i].jobTitle;
							vote.iconPath =
								'https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/cyfw/%E5%AD%B5.png';
							vote.width = 30;
							vote.height = 30;
							var anchor = {};
							anchor.x = 0.5;
							anchor.y = 0.5;
							vote.anchor = anchor;
							// var callout = {};
							// callout.content = incubatorsList[i].jobTitle;
							// callout.borderRadius = 5;
							// callout.display = "ALWAYS";
							// callout.padding = 7;
							// callout.bgColor = "#FFFFFF";
							// vote.callout = callout;
							this.mapData.markers.push(vote);

						}
					} else {

						this.mapData.markers = []
					}

				})

			}

		},
		onLoad() {
			this.imageUrl = this.globalConfig.imageUrl
			this.chosenPosition();
			this.getList();
			this.getListDrop();
			//this.getIncubatorsList()
			this.getAreaBaseList()
		}
	}
</script>

<style lang="scss" scoped>
	$box-shadow: 0 0 10px 0 #efefef;

	.map-content {
		width: 100%;
		height: 100vh;
		position: relative;
		background-color: #F5F9FB;

		map {
			width: 100%;
			height: 100%;
		}

		.article-tab {
			height: 70rpx;
			position: absolute;
			top: 40rpx;
			left: 235rpx;
			z-index: 999;
			box-shadow: 0px 0px 4px 3px #e5e5e5;
		}

		.tab-item {
			width: 50%;
			height: 100%;
			text-align: center;
			background-color: #fff;
			color: red;
			line-height: 70rpx;
		}

		.tab-item.active {
			background-color: red;
			color: #fff;
		}

		.list {
			width: 90%;
			margin: 0 auto;
			padding: 150rpx 0;

			.list-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 220rpx;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx;
				margin-bottom: 30rpx;


				.left {
					width: 80%;
					line-height: 75rpx;

					.title {}

					.site {}

				}

				.right {
					width: 10%;
					display: flex;
					justify-content: right;

					.more {
						width: 65%;
						height: 35%;
					}

					image {
						width: 100%;
						height: 100%;

					}

				}

			}

			.info-list {
				background: linear-gradient(to right, #7254DA, #4E5CDA, #2E63DA);
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				padding: 30rpx;

				.info-item {
					display: flex;
					align-items: center;
					margin-top: 20rpx;

					.info-title {
						color: #fff;
						font-size: 38rpx;
						font-weight: bold;
					}

					.info-icon {
						width: 90rpx;
						height: 90rpx;
						margin-right: 30rpx;
						border-radius: 50%;
					}
				}

				.menu-item {
					display: flex;
					margin-top: 40rpx;

					.menu-list {
						margin-right: 20rpx;
						background-color: #5F96CA;
						padding: 8rpx 11rpx;
						border-radius: 30rpx;

						.menu {
							color: #fff;
							font-size: 28rpx;
						}
					}

					.menu-list:last-child {
						margin-right: 0;
					}
				}
			}

			.info-list:nth-child(2) {
				background: linear-gradient(to right, #3A3985, #4567B2, #5198E1);
			}

			.info-list:nth-child(3) {
				background: linear-gradient(to right, #2A6DD3, #4289AA, #559E8A);
			}

		}




		.content-popup {
			bottom: 0;
			position: fixed;
			left: 0;
			width: 100%;
			z-index: 999999;
			height: 27%;
			background-color: #fff;

			.popup-top {
				padding-top: 46rpx;
				padding-left: 46rpx;
				display: flex;

				.popup-title {
					font-size: 36rpx;
					font-weight: 800;
					width: 85%;
				}

				.popup-x {
					color: #fff;
					width: 50rpx;
					height: 50rpx;
					background-color: #ff7626;
					border-radius: 50rpx;
					font-size: 50rpx;
					line-height: 88%;
					/** 垂直居中 **/
					text-align: center;
					/** 水平居中 **/
				}
			}


		}
	}

	.detailBox {
		position: fixed;
		width: 100%;
		height: auto;
		bottom: 0;
		left: 0;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		overflow-y: auto;
		transition: all .5s;
		z-index: 99999;

		.block.classify-tab-block {
			width: 100%;
			height: 50rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;

			.tab-content {
				display: flex;
				flex-direction: row;
				justify-content: left;

				.tab-item {
					padding: 10rpx 30rpx;
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 20rpx;
					flex: none;
				}

				.tab-item.active {
					background: url("https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/home/tab_selected_bg.png") no-repeat right bottom;
					background-size: 70%;
				}
			}

			.publish-btn {
				width: 45rpx;
			}

			.iconfont {
				font-size: 32rpx;
				font-weight: bold;
				color: #000;
			}
		}

		.block.list-block {

			box-shadow: none;
			display: flex;
			flex-direction: column;
			margin-bottom: 0;

			.list-item {
				background: #fff;
				border-radius: 10rpx;
				box-shadow: $box-shadow;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				margin: 20rpx 40rpx;

				.detail-info {
					width: 260rpx;
					//height: 200rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;

					.name {
						width: 110rpx;
						font-size: 24rpx;
						color: #999;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						text-align: center;
						text-indent: 15rpx;
					}

					.photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.apply-btn {
						border: 1px solid #FE7526;
						border-radius: 8rpx;
						color: #FE7526;
						font-size: 24rpx;
						padding: 8rpx 28rpx;
						position: relative;
						left: 30rpx;
					}
				}

				.list-info {
					// width: calc(100% - 180rpx);
					width: 100%;
					display: flex;
					flex-direction: column;

					>view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.title-info {
						display: flex;
						flex-direction: row;
						align-items: center;

						.title {
							color: #000;
							font-weight: bold;
							font-size: 34rpx;
						}

						.fast-job {
							width: 60rpx;
							height: 38rpx;
							border: 1rpx solid #FE7526;
							font-size: 24rpx;
							text-align: center;
							color: #FE7526;
							margin-left: 20rpx;
							border-radius: 6rpx;
						}
					}

					.detail-item {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.money-item {
							margin-top: 20rpx;

							.wage {
								color: #FE7526;
								font-size: 36rpx;
								font-weight: bold;

								.unit {
									font-size: 28rpx;
									font-weight: normal;
								}
							}
						}

						.detail-info {
							width: 180rpx;
							// height: 200rpx;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							justify-content: center;
							align-items: center;

							.name {
								width: 110rpx;
								font-size: 24rpx;
								color: #999;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								text-align: center;
								text-indent: 15rpx;
							}

							.photo {
								width: 70rpx;
								height: 70rpx;
								border-radius: 100%;
								background: #efefef;
							}

							.apply-btn {
								border: 1px solid #FE7526;
								border-radius: 8rpx;
								color: #FE7526;
								font-size: 24rpx;
								padding: 8rpx 28rpx;
								position: relative;
								left: 30rpx;
							}
						}
					}

					.address-item {
						display: flex;
						justify-content: space-between;

						.address {
							width: 440rpx;
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.distance {
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
						}
					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}

					.wage {
						color: #FE7526;
						font-size: 36rpx;
						font-weight: bold;

						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
			}

		}
	}

	.popLine {
		width: 115rpx;
		height: 10rpx;
		border-radius: 28rpx;
		background-color: #C9CACD;
		margin: 20rpx auto 35rpx;
	}

	.popClose {
		width: calc(100% - 80rpx);
		display: flex;
		justify-content: flex-end;
		margin: 30rpx 40rpx 10rpx 40rpx;
	}

	.btn {
		width: 420rpx;
		height: 70rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #FF7626;
		color: #fff;
		font-size: 28rpx;
		border-radius: 40rpx;
		margin: 0 auto;
		margin-top: 50rpx;
	}
</style>